Conditions | 1 |
Paths | 1 |
Total Lines | 67 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var chai = require('chai'); |
||
13 | describe('Manager', function() { |
||
14 | before( function(done) { |
||
15 | Manager.instance.init() |
||
16 | .then(function () { |
||
17 | |||
18 | this.fixture = { |
||
19 | tag: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf8'), |
||
20 | jsonArticle: fse.readJsonSync(__dirname + '/fixtures/files/article-4.json') |
||
21 | } |
||
22 | done() |
||
23 | |||
24 | }.bind(this)) |
||
25 | }); |
||
26 | |||
27 | it('getStructureAndTemplates()', function() { |
||
28 | const data = Manager.instance.getStructureAndTemplates() |
||
29 | chai.assert.equal(data['templates'][0].name, 'article-each-abe', 'failed !') |
||
30 | chai.assert.equal(data['templates'].length, 7, 'failed !') |
||
31 | }); |
||
32 | |||
33 | it('updateStructureAndTemplates()', function() { |
||
34 | Manager.instance.updateStructureAndTemplates() |
||
35 | const data = Manager.instance.getStructureAndTemplates() |
||
36 | chai.assert.equal(data['templates'][0].name, 'article-each-abe', 'failed !') |
||
37 | chai.assert.equal(data['templates'].length, 7, 'failed !') |
||
38 | }); |
||
39 | |||
40 | it('getList()', function() { |
||
41 | const list = Manager.instance.getList() |
||
42 | chai.assert.equal(list[0].name, 'article-1.json', 'failed !') |
||
43 | chai.assert.equal(list.length, 3, 'failed !') |
||
44 | }); |
||
45 | |||
46 | it('getListWithStatusOnFolder() status publish', function() { |
||
47 | const list = Manager.instance.getListWithStatusOnFolder('publish') |
||
48 | chai.assert.equal(list[0].name, 'article-1.json', 'failed !') |
||
49 | chai.assert.equal(list.length, 2, 'failed !') |
||
50 | }); |
||
51 | |||
52 | it('getListWithStatusOnFolder() status draft', function() { |
||
53 | const list = Manager.instance.getListWithStatusOnFolder('draft') |
||
54 | chai.assert.equal(list.length, 2, 'failed !') |
||
55 | }); |
||
56 | |||
57 | it('getListWithStatusOnFolder() status review', function() { |
||
58 | const list = Manager.instance.getListWithStatusOnFolder('review') |
||
59 | chai.assert.equal(list.length, 0, 'failed !') |
||
60 | }); |
||
61 | |||
62 | it('getListWithStatusOnFolder() status publish /0-1', function() { |
||
63 | const list = Manager.instance.getListWithStatusOnFolder('draft', '0-1') |
||
64 | chai.assert.equal(list[0].name, 'article-2.json', 'failed !') |
||
65 | chai.assert.equal(list.length, 1, 'failed !') |
||
66 | }); |
||
67 | |||
68 | it('addPostInList()', function(done) { |
||
69 | const len = Manager.instance.getList().length |
||
70 | cmsOperations.create('article', '', 'article-4.html', {query: ''}, this.fixture.jsonArticle, false) |
||
71 | .then(function(resSave) { |
||
72 | const json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json')) |
||
73 | const list = Manager.instance.getList() |
||
74 | fse.removeSync(json) |
||
75 | chai.assert.equal(list.length, len + 1, 'failed !') |
||
76 | done() |
||
77 | }.bind(this)); |
||
78 | }); |
||
79 | }); |
||
80 |